<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/xhtml1/strict">
  <xsl:output method="html"/>
  <xsl:template match="/">
		<xsl:apply-templates select="//CoverageDSPriv" />
  </xsl:template>

  <xsl:template match="CoverageDSPriv">
    <h1>
      Coverage Report: 
    </h1>
    <h2>Total Coverage</h2>
    <table border="1" cellSpacing="0" cellPadding="5" >
      <xsl:variable name="covered.lines" select="sum(//CoverageDSPriv/Module/LinesCovered)" />
      <xsl:variable name="uncovered.lines" select="sum(//CoverageDSPriv/Module/LinesNotCovered)" />
      <xsl:variable name="covered.blocks" select="sum(//CoverageDSPriv/Module/BlocksCovered)" />
      <xsl:variable name="uncovered.blocks" select="sum(//CoverageDSPriv/Module/BlocksNotCovered)" />

      <thead style="text-align: center;">
        <td style="background-color: forestGreen; color:white">Covered (%Line)</td>
        <td style="background-color: fireBrick; color: white;">Uncovered (%Lines)</td>
        <td style="background-color: forestGreen; color:white;">Covered (%Blocks)</td>
        <td style="background-color: fireBrick; color: white;">Uncovered (%Blocks)</td>
      </thead>
      <tr style="text-align: center;">
        <td>
          <xsl:value-of select="round($covered.lines div ($uncovered.lines + $covered.lines) * 10000) div 100" />
        </td>
        <td>
          <xsl:value-of select="round($uncovered.lines div ($uncovered.lines + $covered.lines) * 10000) div 100" />
        </td>
        <td>
          <xsl:value-of select="round($covered.blocks div ($uncovered.blocks + $covered.blocks) * 10000) div 100" />
        </td>
        <td>
          <xsl:value-of select="round($uncovered.blocks div ($uncovered.blocks + $covered.blocks) * 10000) div 100" />
        </td>
      </tr>
    </table>
    
    <h2>Modules:</h2>
    <table border="1" cellSpacing="0" cellPadding="5" >

      <thead style="text-align: center;">
      <td>Module</td>
      <td style="background-color: forestGreen; color:white">Covered (Lines)</td>
      <td style="background-color: fireBrick; color: white;">Uncovered (Lines)</td>
        <td style="background-color: darkblue; color: white;">Total Coverage (%Lines)</td>
        <td style="background-color: forestGreen; color:white;">Covered (Blocks)</td>
      <td style="background-color: fireBrick; color: white;">Uncovered (Blocks)</td>
      <td style="background-color: darkblue; color: white;">Total Coverage (%Blocks)</td>
    </thead>
      <xsl:apply-templates select="Module" />
    </table>

  </xsl:template>


  <xsl:template match="//CoverageDSPriv/SourceFileNames">
  </xsl:template>

  <xsl:template match="//CoverageDSPriv/Module">

    <xsl:variable name="covered.lines" select="LinesCovered" />
    <xsl:variable name="uncovered.lines" select="LinesNotCovered" />
    <xsl:variable name="covered.blocks" select="BlocksCovered" />
    <xsl:variable name="uncovered.blocks" select="BlocksNotCovered" />
    <xsl:variable name="Module.Name" select="ModuleName" />
    <tr style="text-align: center;">
      <td style="text-align: left;">
          <xsl:value-of select="ModuleName" />
      </td>
      <td>
          <xsl:value-of select="LinesCovered" />
        </td>
        <td>
          <xsl:value-of select="LinesNotCovered" />
        </td>
        <td>
          <xsl:value-of select="round($covered.lines div ($uncovered.lines+ $covered.lines) * 10000) div 100" />
        </td>
        <td>
          <xsl:value-of select="BlocksCovered" />
        </td>
        <td>
          <xsl:value-of select="BlocksNotCovered" />
        </td>
        <td>
          <xsl:value-of select="round($covered.blocks div ($uncovered.blocks+ $covered.blocks) * 10000) div 100" />
        </td>
      </tr>
  </xsl:template>
</xsl:stylesheet>
